package flex.cc.nursing.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import flex.cc.PublicUtil;
import flex.cc.nursing.dao.AccountDataDao;
import flex.cc.nursing.dto.entity.AccountDataEntity;
import flex.cc.nursing.service.AccountDataService;

/**
*
* @author WANGCONG
* 2022年3月22日下午13:36:52
* @desc 预发核算数据实现层
*/
@Service("accountDataService")
@Transactional(rollbackFor = Exception.class)
public class AccountDataServiceImpl extends ServiceImpl<AccountDataDao, AccountDataEntity> implements AccountDataService {

	@Resource
	private AccountDataDao accountDataDao;
	
	/**
	*
	* @author WANGCONG
	* 2022年3月22日下午16:02:39
	* @desc 数据查询
	*/
	@Override
	public List<AccountDataEntity> queryList(AccountDataEntity accountData) {
		return accountDataDao.queryList(accountData);
	}

	/**
	*
	* @author WANGCONG
	* 2022年3月22日下午16:32:31
	* @desc 数据保存
	*/
	@Override
	public void save(Map<String, Object> reqVo) {
		String flag = "create";
		AccountDataEntity accountData = new AccountDataEntity();
		String uniqueNo = PublicUtil.isNotEmpty(reqVo.get("uniqueNo")) ? reqVo.get("uniqueNo").toString() : null;
		if(PublicUtil.isNotEmpty(uniqueNo)){
			accountData.setUniqueNo(uniqueNo);
			List<AccountDataEntity> dataList = this.queryList(accountData);
			if(dataList.size()>0){
				accountData = dataList.get(0);
				flag = "update";
			}else{
				flag = "create";
			}
		}
		accountData.setSource( PublicUtil.isNotEmpty(reqVo.get("source")) ? reqVo.get("source").toString() : null );
		accountData.setApiSource( PublicUtil.isNotEmpty(reqVo.get("apiSource")) ? reqVo.get("apiSource").toString() : null );
		String cardStatus = PublicUtil.isNotEmpty(reqVo.get("cardStatus")) ? reqVo.get("cardStatus").toString() : null;
		cardStatus = transCardStatus(cardStatus);
		accountData.setCardStatus( cardStatus );
		accountData.setOperateTime( PublicUtil.isNotEmpty(reqVo.get("operateTime")) ? reqVo.get("operateTime").toString() : null );
		accountData.setPid( PublicUtil.isNotEmpty(reqVo.get("pid")) ? reqVo.get("pid").toString() : null );
		accountData.setServiceItemCode( PublicUtil.isNotEmpty(reqVo.get("serviceItemCode")) ? reqVo.get("serviceItemCode").toString() : null );
		accountData.setUniqueNo( PublicUtil.isNotEmpty(reqVo.get("uniqueNo")) ? reqVo.get("uniqueNo").toString() : null );
		accountData.setOrderId( PublicUtil.isNotEmpty(reqVo.get("orderId")) ? reqVo.get("orderId").toString() : null );
		accountData.setSignType( PublicUtil.isNotEmpty(reqVo.get("signType")) ? reqVo.get("signType").toString() : null );
		accountData.setSign( PublicUtil.isNotEmpty(reqVo.get("sign")) ? reqVo.get("sign").toString() : null );
		accountData.setUpdateTime(new Date());
		if("create".equals(flag)){//新增
			accountData.setCreateTime(new Date());
			accountDataDao.insert(accountData);
		}else{//修改
			accountDataDao.update(accountData);
		}
		
	}

	/**
	*
	* @author WANGCONG
	* 2022年3月23日下午15:24:26
	* @desc 车生活操作状态转义
	*/
	public String transCardStatus(String cardStatus) {
    	String result = "";
    	switch (cardStatus) {
			case "0":
				result = "预发放";
				break;
			case "1":
				result = "领取";
				break;
			case "2":
				result = "实发";
				break;
			case "4":
				result = "转移";
				break;
			default:
				break;
		}
    	return result;
	}
	
}
